package com.sdy.supermarket.mq.consumer;

import com.sdy.mq.base.BaseMessageConsumer;
import com.sdy.supermarket.biz.constants.MqConstants;
import com.sdy.supermarket.mq.service.ApprovalMsgFacade;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;

/**
 * @author hyh
 */
@Slf4j
@Component
public class ApporvalMessageConsumer extends BaseMessageConsumer {

    @Autowired
    private ApprovalMsgFacade approvalMsgFacade;

    @Override
    protected boolean consume(MessageExt message) {
        String msgBody = null;
        switch (message.getTags()) {
            case MqConstants.Tags.TAG_UPDATENODEAPPROVALRESULTS:
                msgBody = new String(message.getBody(), Charset.forName(RemotingHelper.DEFAULT_CHARSET));
                boolean resIdState = approvalMsgFacade.setOrderAndResIdState(msgBody);
                log.info("接收到来自流程审批模块发送需求申请单&IP修改申请单状态消息" + msgBody);
                return resIdState;
            default:
                break;
        }
        return true;
    }
}
